package br.com.fa7.entity;

import br.com.fa7.util.LOG;
import br.com.fa7.util.RandomUtil;

public class Fight {
	private Fighter owner;
	private Fighter challenging;
	private Fighter winner;
	private boolean isNewFight;
	
	
	public Fight() {
		setNewFight(true);
		setOwner(new Fighter());
		setChallenging(new Fighter());

		while (getChallenging().getName().equals(getOwner().getName())) {
			setChallenging(new Fighter());
		}
	}

	public String attack() {
		if(isNewFight){
			isNewFight = false;
			
			return "Comeca a luta";
		}
		
		boolean ownerAttack = RandomUtil.getRandomBoolean();
		String attack = ownerAttack ? owner.getName() : challenging.getName();
		attack += " " + new Blow().getHightBlow() + " de ";
		attack += ownerAttack ? challenging.getName() : owner.getName();
		
		if(RandomUtil.isFinishFight()){
			attack += "\n";
			
			attack += ownerAttack ? owner.getName() : challenging.getName();
			attack += " venceu por nocaute";
			
			winner = new Fighter(ownerAttack ? owner.getName() : challenging.getName());
		}

		LOG.log(attack);
		
		return attack;
	}

	public Fighter getChallenging() {
		return challenging;
	}

	public void setChallenging(Fighter challenging) {
		this.challenging = challenging;
	}

	public Fighter getOwner() {
		return owner;
	}

	public void setOwner(Fighter owner) {
		this.owner = owner;
	}

	public Fighter getWinner() {
		return winner;
	}

	public void setWinner(Fighter winner) {
		this.winner = winner;
	}

	public boolean isNewFight() {
		return isNewFight;
	}

	public void setNewFight(boolean isNewFight) {
		this.isNewFight = isNewFight;
	}
}
